// 完善服务依赖
package svc

import (
	"zero-demo-rpc/mall/order/api/internal/config"
	"zero-demo-rpc/mall/user/rpc/user"

	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config  config.Config
	UserRpc user.User
}

func NewServiceContext(c config.Config) *ServiceContext {

	return &ServiceContext{
		Config: c,
		// UserRpc: user.NewUser(zrpc.MustNewClient(c.UserRpc)),
	}
}

func (s *ServiceContext) GetUserRpc() user.User {
	if s.UserRpc != nil {
		return s.UserRpc
	}
	cc, err := zrpc.NewClient(s.Config.UserRpc)
	if err != nil {
		return nil
	}
	s.UserRpc = user.NewUser(cc)
	return s.UserRpc

}
